#include<iostream>
#include<string>
//pointer to function prectice
using namespace std;

typedef double(*lpfn) (double, double); // long pointer function;
double calculate(double a, double b, lpfn fn);
double add (double, double);
double min (double, double);
double mul (double, double);
double div (double, double);

lpfn pf[4]= { add, min, mul, div };//pointer to function array

void main()
{
	double a, b;
	cout << "please input a pair of numbers (could be double, q to quit):__  __\b\b\b\b\b\b";
	while (cin.get() != 'q')
	{
		
		while (!(cin >> a >> b))
		{
			cin.clear();
			while (cin.get() != '\n')
				continue;
			cout << "Bad input, please enter a pair of numbers(could be double, q to quit):__  __\b\b\b\b\b\b";
		}

		cout << "a add b is " << calculate(a, b, *pf[0]) << endl;
		cout << "a minus b is " << calculate(a, b, *pf[1]) << endl;
		cout << "a multiply b is " << calculate(a, b, *pf[2]) << endl;
		cout << "a divided by b is " << calculate(a, b, *pf[3]) << endl;

		cin.clear();
		while (cin.get() != '\n')
			continue;
		cout << "please input a pair of numbers (could be double, q to quit):__  __\b\b\b\b\b\b";

	}
}

double calculate(double a, double b, lpfn pf)
{
	return (*pf) (a, b);
}

double add(double a, double b)
{
	return a + b;
}

double min(double a, double b)
{
	return a - b;
}

double mul(double a, double b)
{
	return a * b;
}

double div(double a, double b)
{
	return a / b;
}
